package com.autumn.zero.workflow.constants;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.autumn.common.api.domain.values.IntegerConstantItemValue;

/**
 * 流程状态
 * 
 * @author 杨昌国 2019-01-24 14:35:27
 */
public class ProcessStatusConstants implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1023481749898432105L;

	/**
	 * 正在启动
	 */
	public static final int STARTING = 1;

	/**
	 * 运行中
	 */
	public static final int EXECUTING = 2;

	/**
	 * 暂停
	 */
	public static final int PAUSE = 3;

	/**
	 * 异常
	 */
	public static final int ERROR = 4;

	/**
	 * 结束
	 */
	public static final int END = 99;

	private static final Map<Integer, IntegerConstantItemValue> NAME_MAP = new HashMap<>();

	static {
		NAME_MAP.put(STARTING, new IntegerConstantItemValue(STARTING, "正在启动", ""));
		NAME_MAP.put(EXECUTING, new IntegerConstantItemValue(EXECUTING, "正在运行", ""));
		NAME_MAP.put(PAUSE, new IntegerConstantItemValue(PAUSE, "暂停", ""));
		NAME_MAP.put(ERROR, new IntegerConstantItemValue(ERROR, "出现异常", ""));
		NAME_MAP.put(END, new IntegerConstantItemValue(END, "结束", ""));
	}

	/**
	 * 是否存在
	 * 
	 * @param value 值
	 * @return
	 */
	public static boolean exist(Integer value) {
		if (value == null) {
			return false;
		}
		return NAME_MAP.containsKey(value);
	}

	/**
	 * 获取名称
	 * 
	 * @param value 值
	 * @return
	 */
	public static String getName(Integer value) {
		IntegerConstantItemValue item = NAME_MAP.get(value);
		if (item == null) {
			return "";
		}
		return item.getName();
	}

	/**
	 * 项目集合
	 * 
	 * @return
	 */
	public static Collection<IntegerConstantItemValue> items() {
		return NAME_MAP.values();
	}
}
